package com.dmall.manager.service.impl;

import com.dmall.manager.mapper.ItemCatMapper;
import com.dmall.pojo.TbItemCat;
import com.dmall.manager.service.ItemCatService;
import com.dmall.utils.EasyUITreeNodeInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

/**
 * 商品类别服务
 * @author Chen 2017/10/12
 */
@Service
public class ItemCatServiceImpl implements ItemCatService {
    @Autowired
    private ItemCatMapper itemCatMapper;

    @Override
    public List<EasyUITreeNodeInfo> getItemCatList(Long parentId) {
        Example example = new Example(TbItemCat.class);
        Example.Criteria criteria = example.createCriteria();
        //根据parentId查询子节点列表
        criteria.andEqualTo("parentId",parentId);
        List<TbItemCat> list = itemCatMapper.selectByExample(example);
        List<EasyUITreeNodeInfo> infos = new ArrayList<>();
        for(TbItemCat tbItemCat :list){
            EasyUITreeNodeInfo info = new EasyUITreeNodeInfo();
            info.setId(tbItemCat.getId());
            info.setState(tbItemCat.getIsParent()?"closed":"open");
            info.setText(tbItemCat.getName());
            infos.add(info);
        }
        return infos;
    }


}
